<?php
/*
NOTE: this file requires WordPress 2.7+ to function
*/
$settings = 'theme_mods_'.get_current_theme(); // do not change!

$defaults = array( // define our defaults
		'top' => 'Yes',
		'top_content' => '',
		'side' => 'Yes',
		'side_content' => '',		
		'side2' => 'Yes',
		'side2_content' => '',		
		'foot' => 'Yes',
		'foot_content' => '',
		'search' => 'No',
		'search_content' => '',		
		'track' => 'No',
		'track_content' => '',
		'single' => 'Yes',
		'single_content' => '',
		'single_top' => 'No',
		'single_top_content' => '',
		'dh_say' => 'No',
		'dh_say_content' => ''		
		 // <-- no comma after the last option
);

//	push the defaults to the options database,
//	if options don't yet exist there.
add_option($settings, $defaults, '', 'yes');

/*
///////////////////////////////////////////////
This section hooks the proper functions
to the proper actions in WordPress
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*/
//	this function registers our settings in the db
add_action('admin_init', 'register_theme_settings');
function register_theme_settings() {
	global $settings;
	register_setting($settings, $settings);
}
//	this function adds the settings page to the Appearance tab
add_action('admin_menu', 'add_theme_options_menu');
function add_theme_options_menu() {
	add_submenu_page('themes.php','dhchannel','dhchannel', 8, 'theme-options', 'theme_settings_admin');
}

function theme_settings_admin() { ?>
<?php theme_options_css_js(); ?>

<div class="wrap">
  <?php
	global $settings, $defaults;
	if(get_theme_mod('reset')) {
		echo '<div class="updated fade" id="message"><p>'.'主题选项'.' <strong>'.'恢复成初始设置'.'</strong></p></div>';
		update_option($settings, $defaults);
	} elseif($_REQUEST['updated'] == 'true') {
		echo '<div class="updated fade" id="message"><p>'.'主题选项'.' <strong>'.'保存成功'.'</strong></p></div>';
	}
	screen_icon('options-general');
?>
  <h2><?php echo get_current_theme() . ' ';?>主题选项</h2>
  <form method="post" action="options.php">
    <?php settings_fields($settings); // important! ?>
    <?php // begin first column ?>
    <div class="metabox-holder">
      <div class="postbox">
        <h3>
          主题信息：
        </h3>
        <div class="inside">
          <p>由主题<a rel="nofollow" href="http://dhblog.org/">DH</a>制作--> <a href="http://dhblog.org" target="_blank">演示</a> --><a href="http://dhblog.org/download/dhchannel.zip">最新下载</a> --> <a rel="nofollow" href="http://dhblog.org" target="_blank">联系方式</a></p>
        </div>
      </div>
	  <div class="postbox">
        <h3>
         网站横幅公告
        </h3>
        <div class="inside">
          <p>
             显示网站横幅公告：
            <select name="<?php echo $settings; ?>[top]">
              <option style="padding-right:10px;" value="Yes" <?php selected('Yes', get_theme_mod('top')); ?>>Yes</option>
              <option style="padding-right:10px;" value="No" <?php selected('No', get_theme_mod('top')); ?>>No</option>
            </select>
          输入你的公告：<br/>        
            <textarea name="<?php echo $settings; ?>[top_content]" cols=80 rows=2><?php echo stripslashes(get_theme_mod('top_content')); ?></textarea>
          </p>
        </div>
      </div>
	  <div class="postbox">
        <h3>
          网站侧边栏广告
        </h3>
        <div class="inside">
          <p>
            显示网站侧边栏广告：
            <select name="<?php echo $settings; ?>[side]">
              <option style="padding-right:10px;" value="Yes" <?php selected('Yes', get_theme_mod('side')); ?>>Yes</option>
              <option style="padding-right:10px;" value="No" <?php selected('No', get_theme_mod('side')); ?>>No</option>
            </select>
            输入代码：<br />
            <textarea name="<?php echo $settings; ?>[side_content]" cols=80 rows=10><?php echo stripslashes(get_theme_mod('side_content')); ?></textarea>
          </p>
        </div>
      </div>
	  <div class="postbox">
        <h3>
          Rss
        </h3>
        <div class="inside">
          <p>
            显示Rss：
            <select name="<?php echo $settings; ?>[side2]">
              <option style="padding-right:10px;" value="Yes" <?php selected('Yes', get_theme_mod('side2')); ?>>Yes</option>
              <option style="padding-right:10px;" value="No" <?php selected('No', get_theme_mod('side2')); ?>>No</option>
            </select>
            输入代码：<br />
            <textarea name="<?php echo $settings; ?>[side2_content]" cols=80 rows=10><?php echo stripslashes(get_theme_mod('side2_content')); ?></textarea>
          </p>
        </div>
      </div>
      <div class="postbox">
        <h3>
          底部友情链接：
        </h3>
        <div class="inside">
          <p>显示底部友情链接：
            <select name="<?php echo $settings; ?>[foot]">
              <option style="padding-right:10px;" value="Yes" <?php selected('Yes', get_theme_mod('foot')); ?>>Yes</option>
              <option style="padding-right:10px;" value="No" <?php selected('No', get_theme_mod('foot')); ?>>No</option>
            </select>
          输入你的代码：<br/>
            <textarea name="<?php echo $settings; ?>[foot_content]" cols=80 rows=10><?php echo stripslashes(get_theme_mod('foot_content')); ?></textarea>
          </p>
        </div>
      </div>
      <div class="postbox">
        <h3>
          google自定义搜索
        </h3>
        <div class="inside">
          <p>使用google自定义搜索：
            <select name="<?php echo $settings; ?>[search]">
              <option style="padding-right:10px;" value="Yes" <?php selected('Yes', get_theme_mod('search')); ?>>Yes</option>
              <option style="padding-right:10px;" value="No" <?php selected('No', get_theme_mod('search')); ?>>No</option>
            </select>
          输入你的代码：<br/>
            <textarea name="<?php echo $settings; ?>[search_content]" cols=80 rows=10><?php echo stripslashes(get_theme_mod('search_content')); ?></textarea>
          </p>
        </div>
      </div>
      <div class="postbox">
        <h3>
         网站统计
        </h3>
        <div class="inside">
          <p>
             使用第三方网站统计：
            <select name="<?php echo $settings; ?>[track]">
              <option style="padding-right:10px;" value="Yes" <?php selected('Yes', get_theme_mod('track')); ?>>Yes</option>
              <option style="padding-right:10px;" value="No" <?php selected('No', get_theme_mod('track')); ?>>No</option>
            </select>
          输入你的代码：<br/>        
            <textarea name="<?php echo $settings; ?>[track_content]" cols=80 rows=10><?php echo stripslashes(get_theme_mod('track_content')); ?></textarea>
          </p>
        </div>
      </div>

      <div class="postbox">
        <h3>
         single文章的底部显示
        </h3>
        <div class="inside">
          <p>
             显示single文章的底部显示：
            <select name="<?php echo $settings; ?>[single]">
              <option style="padding-right:10px;" value="Yes" <?php selected('Yes', get_theme_mod('single')); ?>>Yes</option>
              <option style="padding-right:10px;" value="No" <?php selected('No', get_theme_mod('single')); ?>>No</option>
            </select>
          输入你的代码：<br/>        
            <textarea name="<?php echo $settings; ?>[single_content]" cols=80 rows=10><?php echo stripslashes(get_theme_mod('single_content')); ?></textarea>
          </p>
        </div>
      </div>	  

      <div class="postbox">
        <h3>
         single文章的头部显示
        </h3>
        <div class="inside">
          <p>
             显示single文章的头部显示：
            <select name="<?php echo $settings; ?>[single_top]">
              <option style="padding-right:10px;" value="Yes" <?php selected('Yes', get_theme_mod('single_top')); ?>>Yes</option>
              <option style="padding-right:10px;" value="No" <?php selected('No', get_theme_mod('single_top')); ?>>No</option>
            </select>
          输入你的代码：<br/>        
            <textarea name="<?php echo $settings; ?>[single_top_content]" cols=80 rows=10><?php echo stripslashes(get_theme_mod('single_top_content')); ?></textarea>
          </p>
        </div>
      </div>		  

      <div class="postbox">
        <h3>
         头部名言显示
        </h3>
        <div class="inside">
          <p>
           头部名言显示：
            <select name="<?php echo $settings; ?>[dh_say]">
              <option style="padding-right:10px;" value="Yes" <?php selected('Yes', get_theme_mod('dh_say')); ?>>Yes</option>
              <option style="padding-right:10px;" value="No" <?php selected('No', get_theme_mod('dh_say')); ?>>No</option>
            </select>
           输入你的名言：<br/>        
            <textarea name="<?php echo $settings; ?>[dh_say_content]" cols=80 rows=10><?php echo stripslashes(get_theme_mod('dh_say_content')); ?></textarea>
          </p>
        </div>
      </div>	
	  
	  <div class="submit">
        <input type="submit" class="button-primary" value="保存" />
        <input type="submit" class="button-highlighted" name="<?php echo $settings; ?>[reset]" value="重设" />
      </div>	  
    </div>
  </form>
</div>
<?php }

// add CSS and JS if necessary
function theme_options_css_js() {
echo <<<CSS

<style type="text/css">
	.metabox-holder { 
		width: 700px; 
		float: left;
		margin: 5px;
		padding: 0 10px 0 0;
	}
	.metabox-holder .postbox .inside {
		padding: 0 10px;
	}
	input, textarea, select {
		margin: 5px 0 5px 0;
		padding: 1px;
	}
	.submit{
	   text-align:center;
	}
</style>

CSS;
echo <<<JS

<script type="text/javascript">
jQuery(document).ready(function($) {
	$(".fade").fadeIn(1000).fadeTo(1000, 1).fadeOut(1000);
});
</script>

JS;
}
?>
